﻿var avlmsg = "";
var avlitem = "";
$(function () {

    InitializeAvl();

    prm.add_endRequest(function (s, a) {
        InitializeAvl();
        CallOM(avlmsg);
        CloseJqueryDialog();
        $('input:reset').click();
    });

    PreSelectEndDate();
    
    $('#selectarea select').change(CheckDates);
});

function CheckDates() {
    var ey = $('.endyear').val();
    var em = $('.endmonth').val();
    if (ey != '' && em != '') {
        var start, end;
        var sy = $('.startyear').val();
        var sm = $('.startmonth').val();
        start = MakeDP(sy, sm);
        end = MakeDP(ey, em);
        /*start.setYear(sy);
        start.setMonth(sm);
        start.setDate(1);*/

        if (end >= start) {
            $('.saveitem').show();
        }
        else {

            $('.saveitem').hide();
            alert("开始日期必须早于结束日期。");
        }
    }
}

function MakeDP(y, m) {
    if (m < 10) {
        return y + '0' + m;
    }
    else {
        return y + '' + m;
    }
}

function InitializeAvl() {
    $('.saveitem').click(function() {
        avlmsg = "已添加一条" + avlitem + "经历。"
    });

    $('.deleteitem').click(function() {
        avlmsg = "已删除一条" + avlitem + "经历。"
    });
}

function PreSelectEndDate() {
    $('.endselect').change(function () {
        if (this.value == "") {
            $('.endselect').each(function () {
                this.value = "";
            });
        }
    });
}